﻿using Quartz.Impl;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS_Quartz_Task;
using WCS_Service.DomianService.Interface;

namespace WCS_Service.DomianService
{
    public class SendMsgToSubService : ISendMsgToSubService
    {
        public async Task TimedSendAsync(string msg,Func<string,Task> execute)
        {
            var schedulerFactory = new StdSchedulerFactory();
            var scheduler = await schedulerFactory.GetScheduler();

            var jobDetail = JobBuilder.Create<OpticalJob>().Build();
            jobDetail.JobDataMap.Put("RcsTimedJob", execute);
            jobDetail.JobDataMap.Put("SendMsg", msg);
            var trigger = TriggerBuilder.Create()
                                        .WithSimpleSchedule(m =>
                                        {
                                            m.WithIntervalInSeconds(10).RepeatForever();
                                        })
                                        .StartAt(DateTimeOffset.Now.AddSeconds(5))
                                        .Build();

            //添加心跳任务
            await scheduler.ScheduleJob(jobDetail, trigger);
            await scheduler.Start();
        }
    }
}
